package com.ruyuan.engine.main;
import com.alibaba.fastjson.JSON;
import com.ruyuan.engine.core.RuleEngineProcessDynamic;
import com.ruyuan.engine.pojo.ClientLog;
import com.ruyuan.engine.utils.FlinkKafkaUtils;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 第一个版本主流程测试
 * */
public class RuleMaster {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment environment = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());
        DataStreamSource<String> source = environment.addSource(FlinkKafkaUtils.getKafkaEventSource());
        SingleOutputStreamOperator<ClientLog> source2 = source.map(m -> JSON.parseObject(m, ClientLog.class));
        source2.keyBy(s -> s.getUserNo()).process(new RuleEngineProcessDynamic());
        environment.execute();
    }
}
